home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cchh01.arc
/
JCWFUNC.H
< prev
next >
Wrap
Text File
|
1986-03-14
|
22KB
|
307 lines
/*------------------------------------------------------------------*/
/* JCWFUNC.H -- This is a set of C library routines created by */
/* Weilandt Software International, a subsidiary */
/* of Weilandt Industries Incorporated. */
/* */
/* POINT -- select cursor row and column using ASCII values */
/* CLEAR -- clear the screen */
/* SCREEN -- select screen attributes */
/* EEOL -- erase to end of line */
/* ITOA -- convert an integer to an ASCII string */
/* POSITION -- locate the row and column of the cursor */
/* POINTI -- select cursor row and column using integer values */
/* COLOR -- select screen foreground and background colors */
/* EEOS -- erase to end of screen from cursor position */
/* EHTC -- erase from home position to cursor position */
/* CTRANS -- pseudo translate and test function for strings */
/* */
/*------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/* POINT -- function to move the cursor around the screen using */
/* extended screen management (ANSI.SYS). */
/* */
/* arguments: */
/* row -- pointer to a string variable which contains the */
/* row number to move the cursor to. */
/* column -- pointer to a string variable which contains the */
/* column number to move the curser to. */
/* */
/* example: */
/* point("5","20"); -- moves the cursor to row 5 column 20. */
/* */
/* author: J.C. Weilandt II date: 11-29-84 updated: 11-30-84 */
/*------------------------------------------------------------------*/
point( row, column) /* Define point screen func */
char *row, *column; /* Define string pointers */
{ /* Open the function */
static char csbuf[80] = "\x1B["; /* Define point buffer */
int ret_code; /* define local variable */
strcat(csbuf,row); /* add the row number */
strcat(csbuf,";"); /* add a semi-colon */
strcat(csbuf,column); /* add the column number */
strcat(csbuf,"f"); /* add ANSI function byte */
ret_code = write(1,&csbuf,strlen(csbuf)); /* issue point string */
strcpy(csbuf,"\x1B["); /* reset initial buffer */
} /* Terminate C Function */
/*------------------------------------------------------------------*/
/* CLEAR -- function to clear the screen of the IBM PC using */
/* extended screen management (ANSI.SYS). */
/* */
/* arguments: */
/* none */
/* */
/* example: */
/* clear(); -- clears the screen */
/* */
/* author: J.C. Weilandt II date: 11-29-84 updated: 11-30-84 */
/*------------------------------------------------------------------*/
clear() /* Define clear screen func */
{ /* Open the function */
int ret_code; /* define local variable */
ret_code = write(1,"\x1B[2J",4); /* clear the screen */
} /* Terminate C Function */
/*------------------------------------------------------------------*/
/* SCREEN -- function to change attributes of the PC screen */
/* analagous to the 3270 SF attributes. */
/* */
/* arguments: */
/* attr -- where attr is a string variable containing: */
/* "HIGH" -- High Intensity */
/* "LOW" -- Low Intensity */
/* "NORMAL" -- Low Intensity */
/* "REVERSE" -- Reverse Video */
/* "BLINK" -- Blinking */
/* "INVISIBLE" -- Next field not displayed */
/* */
/* example: */
/* screen("HIGH"); -- sets high intensity mode */
/* */
/* author: J.C. Weilandt II date: 12-01-84 updated: 12-06-84 */
/*------------------------------------------------------------------*/
screen(attr) /* Define screen function */
char *attr; /* Attr is a string pointer */
{ /* Open the function */
int ret_code; /* define local variable */
int max = 1; /* define compare length */
if (strncmp(attr,"H",max) == 0) /* q. selected high ?? */
ret_code = write(1,"\x1B[1m",4); /* yes, issue high seq */
else if (strncmp(attr,"L",max) == 0) /* selected low ?? */
ret_code = write(1,"\x1B[0m",4); /* yes, issue low seq */
else if (strncmp(attr,"N",max) == 0) /* selected low ?? */
ret_code = write(1,"\x1B[0m",4); /* yes, issue low seq */
else if (strncmp(attr,"R",max) == 0) /* selected reverse ?? */
ret_code = write(1,"\x1B[7m",4); /* yes, issue reverse seq */
else if (strncmp(attr,"B",max) == 0) /* selected blink ?? */
ret_code = write(1,"\x1B[5m",4); /* yes, issue blink seq */
else if (strncmp(attr,"I",max) == 0) /* selected invisible ? */
ret_code = write(1,"\x1B[8m",4); /* yes, issue blink seq */
else puts("Invalid Screen Attribute"); /* error message */
} /* Terminate C Function */
/*------------------------------------------------------------------*/
/* EEOL -- function to clear from the cursor to the end of the */
/* current line, extended screen management (ANSI.SYS). */
/* */
/* arguments: */
/* none */
/* */
/* example: */
/* eeol(); -- erase from the cursor to end of line */
/* */
/* author: J.C. Weilandt II date: 12-01-84 updated: 12-01-84 */
/*------------------------------------------------------------------*/
eeol() /* Define eeol screen func */
{ /* Open the function */
int ret_code; /* define local variable */
ret_code = write(1,"\x1B[K",3); /* erase to end of line */
} /* Terminate C Function */
/*------------------------------------------------------------------*/
/* ITOA -- function to create an ASCII string (maximum length */
/* of 10 bytes) from an integer value. */
/* */
/* arguments: */
/* buf -- pointer to the character string in which to store */
/* the ASCII output. */
/* num -- integer value to be converted. */
/* */
/* example: */
/* itoa(buffer,5) -- make digit 5 an ASCII string. */
/* */
/* author: J.C. Weilandt II date: 12-05-84 updated: 12-05-84 */
/*------------------------------------------------------------------*/
itoa(buf, num) /* define ITOA function */
char *buf; /* declare buffer pointer */
int num; /* declare int to convert */
{ /* open the function */
int local; /* declare dummy variable */
local = stcu_d(buf, num, 9); /* invoke system function */
} /* terminate ITOA function */
/*------------------------------------------------------------------*/
/* POSITION -- function to return the row and column position */
/* of the cursor. */
/* */
/* arguments: */
/* row -- integer to receive the current cursor row. */
/* col -- integer to receive the current cursor column. */
/* */
/* example: */
/* position(&row,&col) -- return the row and column values. */
/* */
/* author: J.C. Weilandt II date: 12-06-84 updated: 12-06-84 */
/*------------------------------------------------------------------*/
position(row,col) /* declare function header */
int *row, *col; /* define pointers to integers */
{ /* open function procedure */
char *r, *c; /* define work pointers */
pcvgcp(r,c); /* acquire row and column BIOS */
*row = *r + 1; /* return row to integer */
*col = *c + 1; /* return column to integer */
} /* terminate position function */
/*------------------------------------------------------------------*/
/* POINTI -- function to move the cursor around the screen using */
/* extended screen management (ANSI.SYS). */
/* */
/* arguments: */
/* row -- integer variable containing the row number to */
/* move the cursor to. */
/* column -- integer variable containing the column number to */
/* move the cursor to. */
/* */
/* example: */
/* pointi(5,20); -- moves the cursor to row 5 column 20. */
/* */
/* author: J.C. Weilandt II date: 12-06-84 updated: 12-06-84 */
/*------------------------------------------------------------------*/
pointi(row,col) /* define pointi function */
int row, col; /* declare function arguments */
{ /* open the function structure */
char r_buf[10]; /* define ASCII string holder */
char c_buf[10]; /* define ASCII string holder */
itoa(r_buf,row); /* translate row to ASCII */
itoa(c_buf,col); /* translate column to ASCII */
point(r_buf,c_buf); /* issue normal point function */
} /* close the pointi function */
/*------------------------------------------------------------------*/
/* COLOR -- function to change the foreground and */
/* background colors of the PC screen. */
/* */
/* arguments: */
/* fore -- foreground color string */
/* back -- background color string */
/* */
/* colors: BLACK, RED, GREEN, YELLOW, BLUE, */
/* MAGENTA, CYAN, WHITE */
/* */
/* example: */
/* color("YELLOW","BLUE"); -- yellow on blue background */
/* */
/* author: J.C. Weilandt II date: 12-06-84 updated: 12-07-84 */
/*------------------------------------------------------------------*/
color(col_1,col_2) /* Define color function */
char *col_1, *col_2; /* Declare string pointers */
{ /* Open the function */
int i; /* define loop tester */
int ret_code; /* define local variable */
static char *colors[8] = { /* define color list */
"BLACK","RED","GREEN","YELLOW", /* colors */
"BLUE","MAGENTA","CYAN","WHITE" }; /* more colors */
static char *colorl[8] = { /* define color list */
"black","red","green","yellow", /* colors */
"blue","magenta","cyan","white" }; /* more colors */
static char *fore[8] = { /* define foreground equivs */
"30","31","32","33","34","35","36","37"}; /* equivalents */
static char *back[8] = { /* define background equivs */
"40","41","42","43","44","45","46","47"}; /* equivalents */
static char csbuf[80] = "\x1B["; /* Define color buffer */
for (i=0; i<8; i++) /* Define procedure loop */
{ /* open inner procedure */
if ((strncmp(colors[i],col_1,3) == 0) || /* do we have */
(strncmp(colorl[i],col_1,3) == 0)) /* a match ?? */
{ /* yes, open inner-inner pr */
strcat(csbuf,fore[i]); /* load equivalent */
break; /* terminate the for loop */
} /* terminate inner-inner pr */
} /* close inner procedure */
strcat(csbuf,";"); /* add a semi-colon */
for (i=0; i<8; i++) /* Define procedure loop */
{ /* open inner procedure */
if ((strncmp(colors[i],col_2,3) == 0) || /* do we have */
(strncmp(colorl[i],col_2,3) == 0)) /* a match ?? */
{ /* yes, open inner-inner pr */
strcat(csbuf,back[i]); /* load equivalent */
break; /* terminate the for loop */
} /* terminate inner-inner pr */
} /* close inner procedure */
strcat(csbuf,"m"); /* add ANSI function byte */
ret_code = write(1,&csbuf,strlen(csbuf)); /* issue color string */
strcpy(csbuf,"\x1B["); /* reset initial buffer */
} /* terminate color function */
/*------------------------------------------------------------------*/
/* EEOS -- function to clear from the cursor to the end of the */
/* current screen, extended screen management (ANSI.SYS). */
/* */
/* arguments: */
/* none */
/* */
/* example: */
/* eeos(); -- erase from the cursor to end of screen */
/* */
/* author: J.C. Weilandt II date: 12-23-84 updated: 12-23-84 */
/*------------------------------------------------------------------*/
eeos() /* Define eeos screen func */
{ /* Open the function */
int ret_code; /* define local variable */
ret_code = write(1,"\x1B[0J",4); /* erase to end of screen */
} /* Terminate C Function */
/*------------------------------------------------------------------*/
/* EHTC -- function to clear from the home position to the */
/* cursor position, extended screen management (ANSI.SYS).*/
/* */
/* arguments: */
/* none */
/* */
/* example: */
/* ehtc(); -- erase from home to cursor position */
/* */
/* author: J.C. Weilandt II date: 12-23-84 updated: 12-23-84 */
/*------------------------------------------------------------------*/
ehtc() /* Define ehtc screen func */
{ /* Open the function */
int ret_code; /* define local variable */
ret_code = write(1,"\x1B[1J",4); /* erase to cursor from home */
} /* Terminate C Function */
/*------------------------------------------------------------------*/
/* CTRANS -- function to scan a string and replace every */
/* occurance of one character with another. */
/* */
/* arguments: */
/* string -- character string containing chars to be replaced */
/* old -- character variable for character to be replaced */
/* new -- character variable holding replacement character */
/* */
/* example: */
/* ctrans(string,'_',' '); replace every underscore character */
/* with a blank. */
/* */
/* author: J.C. Weilandt II date: 02-10-85 updated: 02-10-85 */
/*------------------------------------------------------------------*/
ctrans(c_str,old,new) /* Define function and parms */
char *c_str; /* Passed input string */
char old, new; /* passed character vars */
{ /* open C function proper */
char *strchr(); /* define called function */
int r_offset; /* define string offset */
char *offset; /* define actual offset */
int x_test = 0; /* define loop controller */
while (x_test == 0) /* do until all converted */
{ /* open while loop */
offset = strchr(c_str,old); /* point to char for replace */
if (offset == 0) /* Q. are we all done ?? */
{ /* yes, open procedure */
x_test = 1; /* set finished indicator */
break; /* get out of while */
} /* terminate procedure */
r_offset = offset - c_str; /* point to addr of char */
c_str[r_offset] = new; /* replace with new char */
} /* terminate while loop */
} /* terminate C function */